<html>
<head><meta charset="utf-8"><title>co-dependant feature flag dependencies · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html">co-dependant feature flag dependencies</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223177458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223177458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223177458">(Jan 19 2021 at 01:00)</a>:</h4>
<p>Has there been any discussion of a possibility of requiring certain dependencies only when there is a feature flag overlap?</p>
<p>For example, Surf (the http client) would ideally like to have feature flags for the http backend separate of the tls backend.<br>
Currently this would not work well because e.g. a <code>rustls</code> feature would have switch flags for both the <code>async-h1</code> and <code>hyper</code> clients, because it has no way of knowing which http client backend was selected for use.<br>
See <a href="https://github.com/http-rs/surf/pull/271">https://github.com/http-rs/surf/pull/271</a> for an ongoing discussion on Surf's end about how to deal with this.</p>



<a name="223178077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223178077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223178077">(Jan 19 2021 at 01:13)</a>:</h4>
<p>I don't think I follow your suggestion? Do you mean an optional dependency that is activated only if both features are activated?</p>



<a name="223178253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223178253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223178253">(Jan 19 2021 at 01:17)</a>:</h4>
<p>Correct, an optional dependency or feature of an optional dependency which is only active if two specified features are active.</p>
<p>i.e. <code>h1-client</code>+<code>rustls</code> rather than <code>h1-client-rustls</code> (which I think, is the only way to do this today?).</p>



<a name="223178646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223178646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223178646">(Jan 19 2021 at 01:24)</a>:</h4>
<p>This (unstable) feature may help <a href="https://doc.rust-lang.org/cargo/reference/unstable.html#weak-dependency-features">https://doc.rust-lang.org/cargo/reference/unstable.html#weak-dependency-features</a></p>



<a name="223180322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223180322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223180322">(Jan 19 2021 at 02:02)</a>:</h4>
<p>Does that mean that this would only pull in <code>rustls</code> when passed <code>h1-client, rustls</code>?</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[features]</span>
<span class="n">h1-client</span> <span class="o">=</span> <span class="k">["http-client/h1_client", "async-native-tls?", "rustls-tls?"]</span>
<span class="n">rustls-tls</span> <span class="o">=</span> <span class="k">["rustls"]</span>
</code></pre></div>



<a name="223187766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223187766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223187766">(Jan 19 2021 at 05:02)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> Weak dependency features would let you do something like this:</p>
<div class="codehilite" data-code-language="TOML"><pre><span></span><code><span class="k">[features]</span>
<span class="n">rustls</span> <span class="o">=</span> <span class="k">["h1_client?/rustls", "hyper?/rustls"]</span>
</code></pre></div>



<a name="223187781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223187781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223187781">(Jan 19 2021 at 05:02)</a>:</h4>
<p>Which means "activate the rustls feature of h1_client if and only if h1_client is enabled" and "activate the rustls feature of hyper if and only if hyper is enabled".</p>



<a name="223187809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223187809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223187809">(Jan 19 2021 at 05:03)</a>:</h4>
<p>Then you could just enable the HTTP client you want and the TLS stack you want, and you'd get the appropriate feature of the appropriate crate.</p>



<a name="223187816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223187816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223187816">(Jan 19 2021 at 05:03)</a>:</h4>
<p>(You may also want a <code>build.rs</code> script that checks if you pick an impossible combination.)</p>



<a name="223190037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223190037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223190037">(Jan 19 2021 at 06:00)</a>:</h4>
<p>Well that sounds nice - what's the best way of doing this today though?</p>



<a name="223193132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193132">(Jan 19 2021 at 07:07)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> Today, in stable, I don't think you have a better alternative than the client-tls feature-flag pairs.</p>



<a name="223193201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193201">(Jan 19 2021 at 07:09)</a>:</h4>
<p>Well, it's good to have confirmation, since that makes my choices simpler. Unfortunate that this isn't already stable though.</p>



<a name="223193269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193269">(Jan 19 2021 at 07:10)</a>:</h4>
<p><span class="user-mention" data-user-id="319552">@Jeremiah Senkpiel</span> That said, if this solution will work for you, could you give it a try with nightly Cargo, and post an experience report to <a href="https://github.com/rust-lang/cargo/issues/8832">https://github.com/rust-lang/cargo/issues/8832</a> ?</p>



<a name="223193276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193276">(Jan 19 2021 at 07:10)</a>:</h4>
<p>That'll help that feature become stable sooner.</p>



<a name="223193280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193280">(Jan 19 2021 at 07:10)</a>:</h4>
<p>Sure thing, will do.</p>



<a name="223193284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/co-dependant%20feature%20flag%20dependencies/near/223193284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/co-dependant.20feature.20flag.20dependencies.html#223193284">(Jan 19 2021 at 07:10)</a>:</h4>
<p>Thank you!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>